<?php
class FragmentController extends ManageController {

    public function actionIndex() {

        $fragmengs =  $this->connection->createCommand("select * from xm_fragment where lang = '".$this->mgrlang."'")->queryAll();
        $this->data['fragments'] = $fragmengs;

        $this->render ('index',$this->data);
    }

    public function actionDel($id){

        $this->connection->createCommand("delete from xm_fragment where id = {$id}")->query();

        $this->redirect("index");
    }

    public function actionDels(){

        $ids = $_REQUEST['ids'];

        $this->connection->createCommand("delete from xm_fragment where id in ({$ids})")->query();

        echo 1;
    }

    public function actionShowedit($id){

        $this->data['fragment'] = $this->connection->createCommand("select * from xm_fragment where id = {$id}")->queryRow();
        $this->data['id'] = $id;

        $this->render ('showedit',$this->data);
    }

    public function actionEdit(){

        $id = $_REQUEST['id'];
        $key = $_REQUEST['key'];
        $content = $_REQUEST['content'];
        $description = $_REQUEST['description'];

        $this->data['id'] = $id;
        if($id==""){
            //添加
            $this->connection->createCommand(" insert into xm_fragment (`key`,content,description,lang) values ('{$key}','{$content}','{$description}','".$this->mgrlang."') ")->query();
        }else{
            $this->connection->createCommand(" update xm_fragment set `key`='{$key}',content='{$content}',description='{$description}' where id = {$id} ")->query();
        }

        $this->redirect("index");
    }


}
